using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Reflection;

namespace Slaks.TextParsing
{
  using Slaks.Readers;
  using Slaks.Filters;
  using Slaks.Descriptions;

	public class TextFiltering : System.Windows.Forms.Form
	{
    private System.Windows.Forms.OpenFileDialog m_openFileFD;
    private System.Windows.Forms.CheckBox m_readerOptionCB;
    private System.Windows.Forms.Button m_okBtn;
    private System.Windows.Forms.Button m_cancelBtn;
    private System.Windows.Forms.GroupBox m_buttonsGB;
    private System.Windows.Forms.TextBox m_readerModuleTB;
    private System.Windows.Forms.Button m_readerModuleBtn;
    private System.Windows.Forms.TextBox m_textReaderTB;
    private System.Windows.Forms.GroupBox m_readerModuleGB;
    private System.Windows.Forms.ListBox m_readerModuleLB;
    private System.Windows.Forms.TextBox m_readerModuleChosenTB;
    private System.Windows.Forms.Label m_readerModuleL;
    private System.Windows.Forms.GroupBox m_filterModuleGB;
    private System.Windows.Forms.Label m_filterModuleL;
    private System.Windows.Forms.TextBox m_filterModuleChosenTB;
    private System.Windows.Forms.ListBox m_filterModuleLB;
    private System.Windows.Forms.TextBox m_filterModuleTB;
    private System.Windows.Forms.Button m_filterModuleBtn;
    private System.Windows.Forms.TextBox textBox3;


    #region Modules

    private Type m_bufferReader = null;
    private Type m_filter = null;
		private Type m_stopwordCollectionFileReader = null;
		private Type m_stopwordCollectionFilter = null;

    #endregion 
		private System.Windows.Forms.GroupBox m_stopwordModuleGB;
		private System.Windows.Forms.CheckBox m_stopwordModuleCB;
		private System.Windows.Forms.ListBox m_stopwordReaderModuleLB;
		private System.Windows.Forms.Label m_stopwordReaderModuleL;
		private System.Windows.Forms.Button m_stopwordFileBtn;
		private System.Windows.Forms.Button m_stopwordModuleBtn;
		private System.Windows.Forms.TextBox m_stopwordModuleTB;
		private System.Windows.Forms.TextBox m_stopwordFileTB;
		private System.Windows.Forms.OpenFileDialog m_openStopwordFileFD;
		private System.Windows.Forms.TextBox m_stopwordReaderModuleChosenTB;
		private System.Windows.Forms.Label m_stopwordFilterModuleL;
		private System.Windows.Forms.TextBox m_stopwordFilterModuleChosenTB;
		private System.Windows.Forms.ListBox m_stopwordFilterModuleLB;
		private System.Windows.Forms.TextBox m_stopwordFilterModuleTB;
		private System.Windows.Forms.Button m_stopwordFilterModuleBtn;


		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public TextFiltering()
		{
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.m_openFileFD = new System.Windows.Forms.OpenFileDialog();
			this.m_readerOptionCB = new System.Windows.Forms.CheckBox();
			this.m_okBtn = new System.Windows.Forms.Button();
			this.m_cancelBtn = new System.Windows.Forms.Button();
			this.m_buttonsGB = new System.Windows.Forms.GroupBox();
			this.m_readerModuleLB = new System.Windows.Forms.ListBox();
			this.m_readerModuleTB = new System.Windows.Forms.TextBox();
			this.m_readerModuleBtn = new System.Windows.Forms.Button();
			this.m_textReaderTB = new System.Windows.Forms.TextBox();
			this.m_readerModuleGB = new System.Windows.Forms.GroupBox();
			this.m_readerModuleL = new System.Windows.Forms.Label();
			this.m_readerModuleChosenTB = new System.Windows.Forms.TextBox();
			this.m_filterModuleGB = new System.Windows.Forms.GroupBox();
			this.m_filterModuleL = new System.Windows.Forms.Label();
			this.m_filterModuleChosenTB = new System.Windows.Forms.TextBox();
			this.m_filterModuleLB = new System.Windows.Forms.ListBox();
			this.m_filterModuleTB = new System.Windows.Forms.TextBox();
			this.m_filterModuleBtn = new System.Windows.Forms.Button();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.m_stopwordModuleGB = new System.Windows.Forms.GroupBox();
			this.m_stopwordReaderModuleL = new System.Windows.Forms.Label();
			this.m_stopwordReaderModuleChosenTB = new System.Windows.Forms.TextBox();
			this.m_stopwordReaderModuleLB = new System.Windows.Forms.ListBox();
			this.m_stopwordModuleTB = new System.Windows.Forms.TextBox();
			this.m_stopwordModuleBtn = new System.Windows.Forms.Button();
			this.m_stopwordModuleCB = new System.Windows.Forms.CheckBox();
			this.m_stopwordFileTB = new System.Windows.Forms.TextBox();
			this.m_stopwordFileBtn = new System.Windows.Forms.Button();
			this.m_openStopwordFileFD = new System.Windows.Forms.OpenFileDialog();
			this.m_stopwordFilterModuleL = new System.Windows.Forms.Label();
			this.m_stopwordFilterModuleChosenTB = new System.Windows.Forms.TextBox();
			this.m_stopwordFilterModuleLB = new System.Windows.Forms.ListBox();
			this.m_stopwordFilterModuleTB = new System.Windows.Forms.TextBox();
			this.m_stopwordFilterModuleBtn = new System.Windows.Forms.Button();
			this.m_buttonsGB.SuspendLayout();
			this.m_readerModuleGB.SuspendLayout();
			this.m_filterModuleGB.SuspendLayout();
			this.m_stopwordModuleGB.SuspendLayout();
			this.SuspendLayout();
			// 
			// m_openFileFD
			// 
			this.m_openFileFD.DefaultExt = "dll";
			this.m_openFileFD.Filter = "dll files (*.dll)|*.dll|All files (*.*)|*.*";
			this.m_openFileFD.RestoreDirectory = true;
			// 
			// m_readerOptionCB
			// 
			this.m_readerOptionCB.Location = new System.Drawing.Point(16, 16);
			this.m_readerOptionCB.Name = "m_readerOptionCB";
			this.m_readerOptionCB.Size = new System.Drawing.Size(216, 24);
			this.m_readerOptionCB.TabIndex = 3;
			this.m_readerOptionCB.Text = "Toggle the reader and filter support";
			this.m_readerOptionCB.CheckedChanged += new System.EventHandler(this.m_readerOptionCB_CheckedChanged);
			// 
			// m_okBtn
			// 
			this.m_okBtn.Location = new System.Drawing.Point(608, 16);
			this.m_okBtn.Name = "m_okBtn";
			this.m_okBtn.Size = new System.Drawing.Size(64, 24);
			this.m_okBtn.TabIndex = 1;
			this.m_okBtn.Text = "Ok";
			this.m_okBtn.Click += new System.EventHandler(this.m_okBtn_Click);
			// 
			// m_cancelBtn
			// 
			this.m_cancelBtn.Location = new System.Drawing.Point(8, 16);
			this.m_cancelBtn.Name = "m_cancelBtn";
			this.m_cancelBtn.Size = new System.Drawing.Size(64, 24);
			this.m_cancelBtn.TabIndex = 0;
			this.m_cancelBtn.Text = "Cancel";
			this.m_cancelBtn.Click += new System.EventHandler(this.m_cancelBtn_Click);
			// 
			// m_buttonsGB
			// 
			this.m_buttonsGB.Controls.Add(this.m_okBtn);
			this.m_buttonsGB.Controls.Add(this.m_cancelBtn);
			this.m_buttonsGB.Location = new System.Drawing.Point(8, 640);
			this.m_buttonsGB.Name = "m_buttonsGB";
			this.m_buttonsGB.Size = new System.Drawing.Size(680, 48);
			this.m_buttonsGB.TabIndex = 2;
			this.m_buttonsGB.TabStop = false;
			// 
			// m_readerModuleLB
			// 
			this.m_readerModuleLB.Location = new System.Drawing.Point(16, 48);
			this.m_readerModuleLB.Name = "m_readerModuleLB";
			this.m_readerModuleLB.Size = new System.Drawing.Size(656, 30);
			this.m_readerModuleLB.TabIndex = 9;
			this.m_readerModuleLB.DoubleClick += new System.EventHandler(this.m_readerModuleLB_DoubleClick);
			// 
			// m_readerModuleTB
			// 
			this.m_readerModuleTB.Enabled = false;
			this.m_readerModuleTB.Location = new System.Drawing.Point(16, 16);
			this.m_readerModuleTB.Name = "m_readerModuleTB";
			this.m_readerModuleTB.Size = new System.Drawing.Size(512, 20);
			this.m_readerModuleTB.TabIndex = 8;
			this.m_readerModuleTB.Text = "";
			// 
			// m_readerModuleBtn
			// 
			this.m_readerModuleBtn.Enabled = false;
			this.m_readerModuleBtn.Location = new System.Drawing.Point(544, 16);
			this.m_readerModuleBtn.Name = "m_readerModuleBtn";
			this.m_readerModuleBtn.Size = new System.Drawing.Size(128, 24);
			this.m_readerModuleBtn.TabIndex = 2;
			this.m_readerModuleBtn.Text = "Load Reader Module";
			this.m_readerModuleBtn.Click += new System.EventHandler(this.m_readerModuleBtn_Click);
			// 
			// m_textReaderTB
			// 
			this.m_textReaderTB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.m_textReaderTB.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.m_textReaderTB.Location = new System.Drawing.Point(16, -248);
			this.m_textReaderTB.Name = "m_textReaderTB";
			this.m_textReaderTB.Size = new System.Drawing.Size(564, 13);
			this.m_textReaderTB.TabIndex = 1;
			this.m_textReaderTB.Text = "";
			// 
			// m_readerModuleGB
			// 
			this.m_readerModuleGB.BackColor = System.Drawing.SystemColors.Control;
			this.m_readerModuleGB.Controls.Add(this.m_readerModuleL);
			this.m_readerModuleGB.Controls.Add(this.m_readerModuleChosenTB);
			this.m_readerModuleGB.Controls.Add(this.m_readerModuleLB);
			this.m_readerModuleGB.Controls.Add(this.m_readerModuleTB);
			this.m_readerModuleGB.Controls.Add(this.m_readerModuleBtn);
			this.m_readerModuleGB.Controls.Add(this.m_textReaderTB);
			this.m_readerModuleGB.Enabled = false;
			this.m_readerModuleGB.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.m_readerModuleGB.ForeColor = System.Drawing.Color.Blue;
			this.m_readerModuleGB.Location = new System.Drawing.Point(4, 48);
			this.m_readerModuleGB.Name = "m_readerModuleGB";
			this.m_readerModuleGB.Size = new System.Drawing.Size(684, 144);
			this.m_readerModuleGB.TabIndex = 0;
			this.m_readerModuleGB.TabStop = false;
			this.m_readerModuleGB.Text = "Reader module";
			// 
			// m_readerModuleL
			// 
			this.m_readerModuleL.Location = new System.Drawing.Point(16, 88);
			this.m_readerModuleL.Name = "m_readerModuleL";
			this.m_readerModuleL.Size = new System.Drawing.Size(100, 16);
			this.m_readerModuleL.TabIndex = 11;
			this.m_readerModuleL.Text = "Reader module";
			// 
			// m_readerModuleChosenTB
			// 
			this.m_readerModuleChosenTB.Location = new System.Drawing.Point(16, 112);
			this.m_readerModuleChosenTB.Name = "m_readerModuleChosenTB";
			this.m_readerModuleChosenTB.Size = new System.Drawing.Size(656, 20);
			this.m_readerModuleChosenTB.TabIndex = 10;
			this.m_readerModuleChosenTB.Text = "";
			// 
			// m_filterModuleGB
			// 
			this.m_filterModuleGB.Anchor = System.Windows.Forms.AnchorStyles.Left;
			this.m_filterModuleGB.Controls.Add(this.m_filterModuleL);
			this.m_filterModuleGB.Controls.Add(this.m_filterModuleChosenTB);
			this.m_filterModuleGB.Controls.Add(this.m_filterModuleLB);
			this.m_filterModuleGB.Controls.Add(this.m_filterModuleTB);
			this.m_filterModuleGB.Controls.Add(this.m_filterModuleBtn);
			this.m_filterModuleGB.Controls.Add(this.textBox3);
			this.m_filterModuleGB.Enabled = false;
			this.m_filterModuleGB.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.m_filterModuleGB.ForeColor = System.Drawing.Color.Maroon;
			this.m_filterModuleGB.Location = new System.Drawing.Point(6, 200);
			this.m_filterModuleGB.Name = "m_filterModuleGB";
			this.m_filterModuleGB.Size = new System.Drawing.Size(684, 144);
			this.m_filterModuleGB.TabIndex = 4;
			this.m_filterModuleGB.TabStop = false;
			this.m_filterModuleGB.Text = "Filter module";
			// 
			// m_filterModuleL
			// 
			this.m_filterModuleL.Location = new System.Drawing.Point(16, 88);
			this.m_filterModuleL.Name = "m_filterModuleL";
			this.m_filterModuleL.Size = new System.Drawing.Size(136, 16);
			this.m_filterModuleL.TabIndex = 11;
			this.m_filterModuleL.Text = "Desired Filter Module";
			// 
			// m_filterModuleChosenTB
			// 
			this.m_filterModuleChosenTB.Location = new System.Drawing.Point(16, 112);
			this.m_filterModuleChosenTB.Name = "m_filterModuleChosenTB";
			this.m_filterModuleChosenTB.Size = new System.Drawing.Size(656, 20);
			this.m_filterModuleChosenTB.TabIndex = 10;
			this.m_filterModuleChosenTB.Text = "";
			// 
			// m_filterModuleLB
			// 
			this.m_filterModuleLB.Location = new System.Drawing.Point(16, 48);
			this.m_filterModuleLB.Name = "m_filterModuleLB";
			this.m_filterModuleLB.Size = new System.Drawing.Size(656, 30);
			this.m_filterModuleLB.TabIndex = 9;
			this.m_filterModuleLB.DoubleClick += new System.EventHandler(this.m_filterModuleLB_DoubleClick);
			// 
			// m_filterModuleTB
			// 
			this.m_filterModuleTB.Enabled = false;
			this.m_filterModuleTB.Location = new System.Drawing.Point(16, 16);
			this.m_filterModuleTB.Name = "m_filterModuleTB";
			this.m_filterModuleTB.Size = new System.Drawing.Size(512, 20);
			this.m_filterModuleTB.TabIndex = 8;
			this.m_filterModuleTB.Text = "";
			// 
			// m_filterModuleBtn
			// 
			this.m_filterModuleBtn.Enabled = false;
			this.m_filterModuleBtn.Location = new System.Drawing.Point(544, 16);
			this.m_filterModuleBtn.Name = "m_filterModuleBtn";
			this.m_filterModuleBtn.Size = new System.Drawing.Size(128, 24);
			this.m_filterModuleBtn.TabIndex = 2;
			this.m_filterModuleBtn.Text = "Load Filter Module";
			this.m_filterModuleBtn.Click += new System.EventHandler(this.m_filterModuleBtn_Click);
			// 
			// textBox3
			// 
			this.textBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.textBox3.Location = new System.Drawing.Point(16, -248);
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(564, 13);
			this.textBox3.TabIndex = 1;
			this.textBox3.Text = "";
			// 
			// m_stopwordModuleGB
			// 
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordFilterModuleL);
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordFilterModuleChosenTB);
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordFilterModuleLB);
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordFilterModuleTB);
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordFilterModuleBtn);
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordReaderModuleL);
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordReaderModuleChosenTB);
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordReaderModuleLB);
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordModuleTB);
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordModuleBtn);
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordModuleCB);
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordFileTB);
			this.m_stopwordModuleGB.Controls.Add(this.m_stopwordFileBtn);
			this.m_stopwordModuleGB.Enabled = false;
			this.m_stopwordModuleGB.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.m_stopwordModuleGB.ForeColor = System.Drawing.Color.Blue;
			this.m_stopwordModuleGB.Location = new System.Drawing.Point(8, 352);
			this.m_stopwordModuleGB.Name = "m_stopwordModuleGB";
			this.m_stopwordModuleGB.Size = new System.Drawing.Size(680, 280);
			this.m_stopwordModuleGB.TabIndex = 5;
			this.m_stopwordModuleGB.TabStop = false;
			this.m_stopwordModuleGB.Text = "Stopword module";
			// 
			// m_stopwordReaderModuleL
			// 
			this.m_stopwordReaderModuleL.Enabled = false;
			this.m_stopwordReaderModuleL.Location = new System.Drawing.Point(16, 88);
			this.m_stopwordReaderModuleL.Name = "m_stopwordReaderModuleL";
			this.m_stopwordReaderModuleL.Size = new System.Drawing.Size(144, 16);
			this.m_stopwordReaderModuleL.TabIndex = 16;
			this.m_stopwordReaderModuleL.Text = "Desired Reader Module";
			// 
			// m_stopwordReaderModuleChosenTB
			// 
			this.m_stopwordReaderModuleChosenTB.Enabled = false;
			this.m_stopwordReaderModuleChosenTB.Location = new System.Drawing.Point(16, 112);
			this.m_stopwordReaderModuleChosenTB.Name = "m_stopwordReaderModuleChosenTB";
			this.m_stopwordReaderModuleChosenTB.Size = new System.Drawing.Size(648, 20);
			this.m_stopwordReaderModuleChosenTB.TabIndex = 15;
			this.m_stopwordReaderModuleChosenTB.Text = "";
			// 
			// m_stopwordReaderModuleLB
			// 
			this.m_stopwordReaderModuleLB.Location = new System.Drawing.Point(12, 48);
			this.m_stopwordReaderModuleLB.Name = "m_stopwordReaderModuleLB";
			this.m_stopwordReaderModuleLB.Size = new System.Drawing.Size(656, 30);
			this.m_stopwordReaderModuleLB.TabIndex = 14;
			this.m_stopwordReaderModuleLB.DoubleClick += new System.EventHandler(this.m_stopwordReaderModuleLB_DoubleClick);
			// 
			// m_stopwordModuleTB
			// 
			this.m_stopwordModuleTB.Enabled = false;
			this.m_stopwordModuleTB.Location = new System.Drawing.Point(304, 16);
			this.m_stopwordModuleTB.Name = "m_stopwordModuleTB";
			this.m_stopwordModuleTB.Size = new System.Drawing.Size(208, 20);
			this.m_stopwordModuleTB.TabIndex = 13;
			this.m_stopwordModuleTB.Text = "";
			// 
			// m_stopwordModuleBtn
			// 
			this.m_stopwordModuleBtn.Enabled = false;
			this.m_stopwordModuleBtn.Location = new System.Drawing.Point(528, 16);
			this.m_stopwordModuleBtn.Name = "m_stopwordModuleBtn";
			this.m_stopwordModuleBtn.Size = new System.Drawing.Size(136, 24);
			this.m_stopwordModuleBtn.TabIndex = 12;
			this.m_stopwordModuleBtn.Text = "Load Reader Module";
			this.m_stopwordModuleBtn.Click += new System.EventHandler(this.m_stopwordModuleBtn_Click_1);
			// 
			// m_stopwordModuleCB
			// 
			this.m_stopwordModuleCB.Enabled = false;
			this.m_stopwordModuleCB.Location = new System.Drawing.Point(16, 16);
			this.m_stopwordModuleCB.Name = "m_stopwordModuleCB";
			this.m_stopwordModuleCB.Size = new System.Drawing.Size(16, 24);
			this.m_stopwordModuleCB.TabIndex = 11;
			this.m_stopwordModuleCB.CheckedChanged += new System.EventHandler(this.m_stopwordModuleCB_CheckedChanged);
			// 
			// m_stopwordFileTB
			// 
			this.m_stopwordFileTB.Enabled = false;
			this.m_stopwordFileTB.Location = new System.Drawing.Point(40, 16);
			this.m_stopwordFileTB.Name = "m_stopwordFileTB";
			this.m_stopwordFileTB.Size = new System.Drawing.Size(160, 20);
			this.m_stopwordFileTB.TabIndex = 10;
			this.m_stopwordFileTB.Text = "";
			// 
			// m_stopwordFileBtn
			// 
			this.m_stopwordFileBtn.Enabled = false;
			this.m_stopwordFileBtn.Location = new System.Drawing.Point(208, 16);
			this.m_stopwordFileBtn.Name = "m_stopwordFileBtn";
			this.m_stopwordFileBtn.Size = new System.Drawing.Size(88, 24);
			this.m_stopwordFileBtn.TabIndex = 9;
			this.m_stopwordFileBtn.Text = "Stopword File";
			this.m_stopwordFileBtn.Click += new System.EventHandler(this.m_stopwordModuleBtn_Click);
			// 
			// m_openStopwordFileFD
			// 
			this.m_openStopwordFileFD.DefaultExt = "txt";
			this.m_openStopwordFileFD.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
			this.m_openStopwordFileFD.RestoreDirectory = true;
			// 
			// m_stopwordFilterModuleL
			// 
			this.m_stopwordFilterModuleL.Enabled = false;
			this.m_stopwordFilterModuleL.Location = new System.Drawing.Point(12, 224);
			this.m_stopwordFilterModuleL.Name = "m_stopwordFilterModuleL";
			this.m_stopwordFilterModuleL.Size = new System.Drawing.Size(140, 16);
			this.m_stopwordFilterModuleL.TabIndex = 21;
			this.m_stopwordFilterModuleL.Text = "Desired Filter Module";
			// 
			// m_stopwordFilterModuleChosenTB
			// 
			this.m_stopwordFilterModuleChosenTB.Enabled = false;
			this.m_stopwordFilterModuleChosenTB.Location = new System.Drawing.Point(12, 248);
			this.m_stopwordFilterModuleChosenTB.Name = "m_stopwordFilterModuleChosenTB";
			this.m_stopwordFilterModuleChosenTB.Size = new System.Drawing.Size(656, 20);
			this.m_stopwordFilterModuleChosenTB.TabIndex = 20;
			this.m_stopwordFilterModuleChosenTB.Text = "";
			// 
			// m_stopwordFilterModuleLB
			// 
			this.m_stopwordFilterModuleLB.Location = new System.Drawing.Point(12, 184);
			this.m_stopwordFilterModuleLB.Name = "m_stopwordFilterModuleLB";
			this.m_stopwordFilterModuleLB.Size = new System.Drawing.Size(656, 30);
			this.m_stopwordFilterModuleLB.TabIndex = 19;
			this.m_stopwordFilterModuleLB.DoubleClick += new System.EventHandler(this.m_stopwordFilterModuleLB_DoubleClick);
			// 
			// m_stopwordFilterModuleTB
			// 
			this.m_stopwordFilterModuleTB.Enabled = false;
			this.m_stopwordFilterModuleTB.Location = new System.Drawing.Point(12, 152);
			this.m_stopwordFilterModuleTB.Name = "m_stopwordFilterModuleTB";
			this.m_stopwordFilterModuleTB.Size = new System.Drawing.Size(512, 20);
			this.m_stopwordFilterModuleTB.TabIndex = 18;
			this.m_stopwordFilterModuleTB.Text = "";
			// 
			// m_stopwordFilterModuleBtn
			// 
			this.m_stopwordFilterModuleBtn.Enabled = false;
			this.m_stopwordFilterModuleBtn.Location = new System.Drawing.Point(540, 152);
			this.m_stopwordFilterModuleBtn.Name = "m_stopwordFilterModuleBtn";
			this.m_stopwordFilterModuleBtn.Size = new System.Drawing.Size(128, 24);
			this.m_stopwordFilterModuleBtn.TabIndex = 17;
			this.m_stopwordFilterModuleBtn.Text = "Load Filter Module";
			this.m_stopwordFilterModuleBtn.Click += new System.EventHandler(this.m_stopwordFilterModuleBtn_Click);
			// 
			// TextFiltering
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(696, 694);
			this.Controls.Add(this.m_stopwordModuleGB);
			this.Controls.Add(this.m_filterModuleGB);
			this.Controls.Add(this.m_readerOptionCB);
			this.Controls.Add(this.m_buttonsGB);
			this.Controls.Add(this.m_readerModuleGB);
			this.Name = "TextFiltering";
			this.Text = "Text Filtering Support";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.TextFiltering_Closing);
			this.m_buttonsGB.ResumeLayout(false);
			this.m_readerModuleGB.ResumeLayout(false);
			this.m_filterModuleGB.ResumeLayout(false);
			this.m_stopwordModuleGB.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

    /// <summary>
    /// Checks if the reader module will be used 
    /// </summary>
    public bool ISUseReaderAndFilterModules
    {
      get { return m_readerOptionCB.Checked; }
    }

    private void m_readerModuleBtn_Click(object sender, System.EventArgs e)
    {
      m_openFileFD.Title = "Load text reader";
      string file = null;
      try
      {
        if (m_openFileFD.ShowDialog() == DialogResult.OK)
        {
          file = m_openFileFD.FileName;
          m_readerModuleTB.Text = file;
					m_stopwordModuleTB.Text = file;
          ReadModuleDescriptionForReaderFilter(true,file,m_readerModuleLB);
					ReadModuleDescriptionStopwordsFileReader(file);
        }
      }
      catch(Exception ex)
      {
        MessageBox.Show(this,ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
      }
    }


		private void ReadModuleDescriptionStopwordsFileReader(string filename)
		{
			try
			{
				Assembly moduleAssembly = Assembly.LoadFrom(filename);
        
				Type [] types = moduleAssembly.GetTypes();

				IList descriptions = new ArrayList();
				AttributeDescriptionWrapper wrapper = null;

				for (int i=0;i<types.Length;i++)
				{
					if (types[i].BaseType != typeof(FileReader)) continue;

					object [] moduleDescritption = types[i].GetCustomAttributes(typeof(ModuleDescriptionAttribute),true);
					if (moduleDescritption != null && moduleDescritption.Length > 0)
					{
						wrapper = new AttributeDescriptionWrapper(types[i],(ModuleDescriptionAttribute)moduleDescritption[0]);
						descriptions.Add(wrapper);
					}
				}
				m_stopwordReaderModuleLB.DataSource = descriptions;
			}
			catch(Exception ex)
			{
				MessageBox.Show(null,ex.Message,"Assembly error",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
		}
    
		private void ReadModuleDescriptionForReaderFilter(bool isReader,string filename,ListBox listBox)
    {
        try
        {
          Assembly moduleAssembly = Assembly.LoadFrom(filename);
        
          Type [] types = moduleAssembly.GetTypes();

          IList descriptions = new ArrayList();
          AttributeDescriptionWrapper wrapper = null;

          for (int i=0;i<types.Length;i++)
          {
            if (isReader)
            {
              if (!this.IsTypeOf(types[i].BaseType,typeof(BufferReader))) continue;
            }
            else
            {
              if (!this.IsTypeOf(types[i].BaseType,typeof(AFilter))) continue;
            }

            object [] moduleDescritption = types[i].GetCustomAttributes(typeof(ModuleDescriptionAttribute),true);
            if (moduleDescritption != null && moduleDescritption.Length > 0)
            {
              wrapper = new AttributeDescriptionWrapper(types[i],(ModuleDescriptionAttribute)moduleDescritption[0]);
              descriptions.Add(wrapper);
            }
          }
          listBox.DataSource = descriptions;
          
        }
        catch(Exception ex)
        {
          MessageBox.Show(null,ex.Message,"Assembly error",MessageBoxButtons.OK,MessageBoxIcon.Error);
        }
    }

    private bool IsTypeOf(Type checkType, Type baseType)
    {
      if (checkType == typeof(Object)) return false;
      if (checkType == baseType) return true;
      return IsTypeOf(checkType.BaseType,baseType);
    }


    private void m_readerOptionCB_CheckedChanged(object sender, System.EventArgs e)
    {
       EnableControls(m_readerOptionCB.Checked);
    }

    private void EnableControls(bool enable)
    {
        m_readerModuleBtn.Enabled = 
        m_readerModuleChosenTB.Enabled = 
        m_readerModuleLB.Enabled = 
        m_readerModuleTB.Enabled = 
        m_readerModuleLB.Enabled = 
        m_readerModuleGB.Enabled = 
        m_filterModuleBtn.Enabled = 
        m_filterModuleLB.Enabled = 
        m_filterModuleGB.Enabled = 
        m_filterModuleLB.Enabled =
        m_filterModuleChosenTB.Enabled = 
        m_filterModuleTB.Enabled = 
				m_stopwordModuleCB.Enabled =
				m_stopwordModuleGB.Enabled = 
					enable;
    }

    private void m_filterModuleBtn_Click(object sender, System.EventArgs e)
    {
      m_openFileFD.Title = "Load text filter";
      string file = null;
      try
      {
        if (m_openFileFD.ShowDialog() == DialogResult.OK)
        {
          file = m_openFileFD.FileName;
          m_filterModuleTB.Text = file;
					m_stopwordFilterModuleTB.Text = file;
          ReadModuleDescriptionForReaderFilter(false,file,m_filterModuleLB);
					ReadModuleDescriptionForReaderFilter(false,file,m_stopwordFilterModuleLB);
        }
      }
      catch(Exception ex)
      {
        MessageBox.Show(this,ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
      }
    }

    private void m_readerModuleLB_DoubleClick(object sender, System.EventArgs e)
    {
      int index = m_readerModuleLB.SelectedIndex;
      if (index < 0) return;
      AttributeDescriptionWrapper a = (AttributeDescriptionWrapper) m_readerModuleLB.SelectedItem;
      m_readerModuleChosenTB.Text = a.ToString();
      m_bufferReader = (Type) a.DescriptionObject;
    }

    private void m_filterModuleLB_DoubleClick(object sender, System.EventArgs e)
    {
      int index = m_filterModuleLB.SelectedIndex;
      if (index < 0) return; 
      AttributeDescriptionWrapper a = (AttributeDescriptionWrapper) m_filterModuleLB.SelectedItem;
      m_filterModuleChosenTB.Text = a.ToString();
      m_filter = (Type) a.DescriptionObject;
    }

    private void m_okBtn_Click(object sender, System.EventArgs e)
    {
      if (!this.ISUseReaderAndFilterModules) 
      {
        this.Hide();
        return;
      }

			if (m_readerModuleChosenTB.Text == String.Empty ||
				m_filterModuleChosenTB.Text == String.Empty)
			{
				MessageBox.Show(this,"Some of the modules were not chosen","Modules Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
			else
			{
				if (this.ISUseStopwordCollectionModule)
				{
					if (m_stopwordReaderModuleChosenTB.Text == String.Empty || m_stopwordFilterModuleChosenTB.Text == String.Empty)
					{
						MessageBox.Show(this,"Some of the stopword modules were not chosen","Stopword Modules Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
					}
					else if (m_stopwordFileTB.Text == String.Empty)
					{
						MessageBox.Show(this,"Provide path and filename for stopword collection","Stopword File Collection Missing",MessageBoxButtons.OK,MessageBoxIcon.Warning);
					}
					else
					{
						this.Hide();
					}
				}
				else
				{
					this.Hide();
				}
			}
    }

    private void TextFiltering_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
      if (!this.ISUseReaderAndFilterModules) 
      {
        this.Hide();
        return;
      }

      e.Cancel = true;

			if (m_readerModuleChosenTB.Text == String.Empty ||
				m_filterModuleChosenTB.Text == String.Empty)
			{
				MessageBox.Show(this,"Some of the modules were not chosen","Modules Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
			else
			{
				if (this.ISUseStopwordCollectionModule)
				{
					if (m_stopwordReaderModuleChosenTB.Text == String.Empty || m_stopwordFilterModuleChosenTB.Text == String.Empty)
					{
						MessageBox.Show(this,"Some of the stopword modules were not chosen","Stopword Modules Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
					}
					else if (m_stopwordFileTB.Text == String.Empty)
					{
						MessageBox.Show(this,"Provide path and filename for stopword collection","Stopword File Collection Missing",MessageBoxButtons.OK,MessageBoxIcon.Warning);
					}
					else
					{
						this.Hide();
					}
				}
				else
				{
					this.Hide();
				}
			}
    }

    private void m_cancelBtn_Click(object sender, System.EventArgs e)
    {
      if (!this.ISUseReaderAndFilterModules) 
      {
        this.Hide();
        return;
      }
      

			if (m_readerModuleChosenTB.Text == String.Empty ||
				m_filterModuleChosenTB.Text == String.Empty) 
			{
				m_readerOptionCB.Checked = false;
				m_stopwordModuleCB.Checked = false;
				
			}
			else
			{
				if (this.ISUseStopwordCollectionModule)
				{
					if (m_stopwordReaderModuleChosenTB.Text == String.Empty || 
						  m_stopwordFilterModuleChosenTB.Text == String.Empty || 
						  m_stopwordFileTB.Text == String.Empty)
						
					   m_readerOptionCB.Checked = false;
					   m_stopwordModuleCB.Checked = false;
				}
			}

      this.Hide();
    }

		private void m_stopwordModuleCB_CheckedChanged(object sender, System.EventArgs e)
		{
			m_stopwordModuleBtn.Enabled = 
				m_stopwordModuleTB.Enabled = 
				m_stopwordFileBtn.Enabled = 	
				m_stopwordFileTB.Enabled = 
				m_stopwordFilterModuleChosenTB.Enabled =
				m_stopwordFilterModuleL.Enabled = 
				m_stopwordReaderModuleL.Enabled = 
				m_stopwordFilterModuleTB.Enabled = 
				m_stopwordFilterModuleBtn.Enabled =
				m_stopwordReaderModuleChosenTB.Enabled =
				m_stopwordModuleCB.Checked;
			if (m_stopwordModuleCB.Checked == false) Slaks.Filters.Extended.StopwordCollection.ResetSingleton();
		}

		private void m_stopwordModuleBtn_Click(object sender, System.EventArgs e)
		{
			string file = null;
			try
			{
				if (m_openStopwordFileFD.ShowDialog() == DialogResult.OK)
				{
					file = m_openStopwordFileFD.FileName;
					m_stopwordFileTB.Text = file;
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(this,ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
		}

		private void m_stopwordModuleBtn_Click_1(object sender, System.EventArgs e)
		{
			m_openFileFD.Title = "Load FileReader module for stopword collection";
			string file = null;
			try
			{
				if (m_openFileFD.ShowDialog() == DialogResult.OK)
				{
					file = m_openFileFD.FileName;
					m_stopwordModuleTB.Text = file;
					ReadModuleDescriptionStopwordsFileReader(file);
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(this,ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
		}

		private void m_stopwordReaderModuleLB_DoubleClick(object sender, System.EventArgs e)
		{
			int index = m_stopwordReaderModuleLB.SelectedIndex;
			if (index < 0) return;

			AttributeDescriptionWrapper a = (AttributeDescriptionWrapper) m_stopwordReaderModuleLB.SelectedItem;
			m_stopwordReaderModuleChosenTB.Text = a.DescriptionAttribute.ToString();
			m_stopwordCollectionFileReader = (Type)a.DescriptionObject;
		}

		private void m_stopwordFilterModuleBtn_Click(object sender, System.EventArgs e)
		{
			m_openFileFD.Title = "Load stopword filter";
			string file = null;
			try
			{
				if (m_openFileFD.ShowDialog() == DialogResult.OK)
				{
					file = m_openFileFD.FileName;
					m_stopwordFileTB.Text = file;
					ReadModuleDescriptionForReaderFilter(false,file,m_stopwordFilterModuleLB);
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(this,ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
		}

		private void m_stopwordFilterModuleLB_DoubleClick(object sender, System.EventArgs e)
		{
			int index = m_stopwordFilterModuleLB.SelectedIndex;
			if (index < 0) return;

			AttributeDescriptionWrapper a = (AttributeDescriptionWrapper) m_stopwordFilterModuleLB.SelectedItem;
			m_stopwordFilterModuleChosenTB.Text = a.DescriptionAttribute.ToString();
			m_stopwordCollectionFilter = (Type) a.DescriptionObject;
		}

		public bool ISUseStopwordCollectionModule
		{
			get { return m_stopwordModuleCB.Checked; }
		}

		public string StopwordCollectionFileName
		{
			get { return m_stopwordFileTB.Text; }
		}

    public Type BufferReader
    {
      get { return m_bufferReader; }
    }

    public Type Filter
    {
      get { return m_filter; }
    }

		public Type StopwordCollectionFilter
		{
			get { return m_stopwordCollectionFilter; }
		}

		public Type StopwordCollectionFileReader
		{
			get { return m_stopwordCollectionFileReader; }
		}

	}
}
